package com.answer.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 配置类，注册web层相关组件
 */
@Configuration
@Slf4j
// public class WebMvcConfiguration extends WebMvcConfigurationSupport {

public class WebMvcConfiguration implements WebMvcConfigurer {
    static final String ORIGINS[] = new String[] { "GET", "POST", "PUT", "DELETE" };
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedOriginPatterns("*")
                .allowedMethods(ORIGINS)
                .maxAge(3600);
    }


    /**
     * 注册自定义拦截器
     *
     * @param registry
     */
  /*  @Resource
    private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;

    *//**
     * 注册自定义拦截器
     *
     * @param registry
     *//*
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtTokenAdminInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/emp/login");

    }*/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置拦截器访问静态资源
        registry.addResourceHandler("/doc.html","/swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/v3/**")
                .addResourceLocations("classpath:/META-INF/resources/v3/");

        registry.addResourceHandler("/static/user_images/**")
                .addResourceLocations("file:D:/user_images/");
        //.addResourceLocations("classpath:/static/images/");
    }
}
